package org.alex.sample.model;

import java.io.Serializable;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;

import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.constraints.Range;

@Entity
@Table(name = "exam_subject")
public class Subject implements Serializable{

	private static final long serialVersionUID = 1L;

	@Id
	@GeneratedValue
	@Column(name = "sub_id", nullable = false)
	private Integer subId;
	
	@Column(name = "name", nullable = false)
	@Length(min = 1, max = 100, message = "考试科目名称不能为空")
	private String name;
	
	@Column(name = "description", nullable = false)
	private String description;
	
	@Column(name = "test_count", nullable = false)
	@NotNull(message = "请填入考试题数量")
	private Integer testCount;
	
	@Column(name = "total_time", nullable = false)
	@NotNull(message = "考试时间不能为空")
	private Integer totalTime;
	
	@Column(name = "total_score", nullable = false)
	@Range(min = 1, max = 300, message = "科目总分数不能为空")
	private double totalScore;
	
	@Column(name = "status", nullable = false)
	@NotNull(message = "请输入'0'(否),'1'(是)表示考试状态")
	private Integer status;
	
	@OneToMany(mappedBy = "subject", fetch = FetchType.EAGER)
	private Set<ExamTest> examTest;
	
	@OneToMany(mappedBy = "subject")
	private Set<ExamUserSubject> examUserSubject;
	
	@OneToMany(mappedBy = "subject")
	private Set<ExamScore> examScore;
	
	public Subject(Integer subId, String name, String description, Integer testCount, Integer tatalTime, 
			double totalScore, Integer status, Set<ExamTest> examTest, Set<ExamUserSubject> examUserSubject){
		this.subId = subId;
		this.name = name;
		this.description = description;
		this.testCount = testCount;
		this.totalTime = tatalTime;
		this.totalScore = totalScore;
		this.status = status;
		this.examTest = examTest;
		this.examUserSubject = examUserSubject;
	}
	
	public Subject(){
		
	}

	public Integer getSubId() {
		return subId;
	}

	public void setSubId(Integer subId) {
		this.subId = subId;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public Integer getTestCount() {
		return testCount;
	}

	public void setTestCount(Integer testCount) {
		this.testCount = testCount;
	}

	public Integer getTotalTime() {
		return totalTime;
	}

	public void setTotalTime(Integer totalTime) {
		this.totalTime = totalTime;
	}

	public double getTotalScore() {
		return totalScore;
	}

	public void setTotalScore(double totalScore) {
		this.totalScore = totalScore;
	}

	public Integer getStatus() {
		return status;
	}

	public void setStatus(Integer status) {
		this.status = status;
	}

	public Set<ExamTest> getExamTest() {
		return examTest;
	}

	public void setExamTest(Set<ExamTest> examTest) {
		this.examTest = examTest;
	}

	public Set<ExamUserSubject> getExamUserSubject() {
		return examUserSubject;
	}

	public void setExamUserSubject(Set<ExamUserSubject> examUserSubject) {
		this.examUserSubject = examUserSubject;
	}

	public Set<ExamScore> getExamScore() {
		return examScore;
	}

	public void setExamScore(Set<ExamScore> examScore) {
		this.examScore = examScore;
	}
	

}
